using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using System;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Text;
using yW5Lib;

namespace yWriter6
{
	[StandardModule]
	internal sealed class modExportOutline
	{
		public static void ExportOutline(ref clsProject cProject)
		{
			StringBuilder stringBuilder = new StringBuilder();
			string text = Path.Combine(cProject.ProjectPath(), "auto_outline.txt");
			try
			{
				IEnumerator enumerator = default(IEnumerator);
				try
				{
					enumerator = cProject.Chapters.GetEnumerator();
					while (enumerator.MoveNext())
					{
						clsChapter clsChapter = (clsChapter)enumerator.Current;
						stringBuilder.AppendLine("[chapter] " + clsChapter.Title + ".");
						int sceneCount = clsChapter.SceneCount;
						for (int i = 1; i <= sceneCount; i++)
						{
							try
							{
								clsScene clsScene = cProject.get_SceneByChID(clsChapter.ID, i);
								stringBuilder.AppendLine("[scene] " + clsScene.Title + ".");
								stringBuilder.AppendLine(clsScene.DescText);
								stringBuilder.AppendLine("");
							}
							catch (Exception ex)
							{
								ProjectData.SetProjectError(ex);
								Exception ex2 = ex;
								clsShared.cLog.AddAction(ex2, MethodBase.GetCurrentMethod());
								ProjectData.ClearProjectError();
							}
						}
					}
				}
				finally
				{
					if (enumerator is IDisposable)
					{
						(enumerator as IDisposable).Dispose();
					}
				}
				try
				{
					clsShared.cFile.SaveTextFile(text, stringBuilder.ToString(), UseSystemEncoding: true);
					clsShared.cLang.TransMsgBox("Outline saved to @1@", MsgBoxStyle.OkOnly, "", text);
				}
				catch (Exception ex3)
				{
					ProjectData.SetProjectError(ex3);
					Exception ex4 = ex3;
					clsShared.cLang.TransMsgBox("Unable to save output file", MsgBoxStyle.Exclamation);
					clsShared.cLog.AddAction(ex4, MethodBase.GetCurrentMethod());
					ProjectData.ClearProjectError();
				}
			}
			catch (Exception ex5)
			{
				ProjectData.SetProjectError(ex5);
				Exception ex6 = ex5;
				clsShared.cLog.AddAction(ex6, MethodBase.GetCurrentMethod());
				ProjectData.ClearProjectError();
			}
		}
	}
}
